package utils

import (
	"regexp"
)

func GroupFirstStr(reg *regexp.Regexp, str string, group int) string {

	findAll := reg.FindAllStringSubmatch(str, 1)
	for _, s := range findAll {
		for i, v := range s {
			if i == group {
				return v
			}
		}

	}
	return ""
}

func GroupAllStr(reg *regexp.Regexp, str string, group int) []string {

	var arr []string
	findAll := reg.FindAllStringSubmatch(str, -1)
	for _, s := range findAll {
		for i, v := range s {
			if i == group {
				arr = append(arr, v)
			}
		}

	}
	return arr
}

func GroupFirst(reg *regexp.Regexp, str []byte, group int) []byte {
	findAll := reg.FindAllSubmatch(str, 1)
	for _, s := range findAll {
		for i, v := range s {
			if i == group {
				return v
			}
		}

	}
	return nil
}
